/******************************************************************************
 cnome: A C++ source "genes" discover. :-)

 See more details at:

   http://www.codeplex.com/cnome

 The original author site is at: http://www.alemosbarbosa.com/

 Copyright (c) 2010 Alexandre Lemos Barbosa.
 Distributed under the MIT License. (See accompanying file LICENSE-MIT.txt 
 or at http://www.codeplex.com/cnome/license)
 ******************************************************************************/

#ifndef ITERATOR_H
#define ITERATOR_H

#include <boost/iterator/iterator_adaptor.hpp>

#include "typedefs.h"

namespace cnome {
class iterator : public boost::iterator_adaptor<iterator, iterator_T>  {
private:
    struct enabler {};  // a private type avoids misuse

public:
    iterator() : iterator::iterator_adaptor_(), m_pos(0) {}
    iterator(iterator const& other)
      : iterator::iterator_adaptor_(other.base()), m_pos(other.m_pos) {}
    iterator(base_type const& p);

    std::size_t get_cnome_position() const { return m_pos; }
    const iterator& getFarest() { return *m_farest; }

    static const iterator end;

private:
    friend class boost::iterator_core_access;

    std::size_t m_pos;
    static iterator *m_farest;

    void handleMSASM();

    token_t& dereference() const;
    void increment();

    friend bool operator<(const iterator& a, const iterator& b);
    friend bool operator==(const iterator& a, const iterator& b);
};

bool operator<(const iterator& a, const iterator& b);
bool operator==(const iterator& a, const iterator& b);
}  // namespace cnome

#endif // ITERATOR_H
